﻿using UnityEngine;
using UnityEngine.Events;

namespace UnityView
{
    public class UIDialog : AbsDialog
    {
        public static void ShowDialog(string title)
        {
        }
        
        public static void ShowDialog(string title, string pTitle, UnityAction pAction, bool onMask = true)
        {
            UIDialog dialog = new UIDialog(title, pTitle, pAction, "取消", null);
            dialog.Show();
        }

        public static void ShowDialog(string title, string pTitle, UnityAction pAction, string nTitle, UnityAction nAction)
        {
        }
        
        public static Vector2 DefaultButtonSize = new Vector2(120f, 36f);

        public TextView Title;
        public ButtonView PositiveButtonView;
        public ButtonView NegativeButtonView;

        public UIDialog(string title, string pTitle, UnityAction pAction, string nTitle, UnityAction nAction)
        {
            if (DefaultBackgroundSprite != null)
            {
                ContentView.BackgroundSprite = DefaultBackgroundSprite;
            }
            else
            {
                ContentView.BackgroundColor = Color.white;
            }

            Title = new TextView(ContentView, "Dialog Title")
            {
                AnchorAlignment = AnchorAlignment.CentralTop,
                Frame = new Frame(0, 0, DefaultWidth, DefaultHeight - DefaultButtonSize.y),
                Text = title,
                TextColor = Color.black,
                TextAlignment = TextAnchor.MiddleCenter,
                FontSize = 24
            };

            PositiveButtonView = new ButtonView(ContentView, "Positive Button")
            {
                AnchorAlignment = AnchorAlignment.BottomLeft,
                Frame = new Frame(30, 30, DefaultButtonSize.x, DefaultButtonSize.y),
                BackgroundColor = Color.gray,
                Title = pTitle,
                FontSize = 20
            };
            
            if (pAction != null)
            {
                PositiveButtonView.AddListener(pAction);
            }
            PositiveButtonView.AddListener(Destroy);

            NegativeButtonView = new ButtonView(ContentView, "Negative Button")
            {
                AnchorAlignment = AnchorAlignment.BottomRight,
                Frame = new Frame(30, 30, DefaultButtonSize.x, DefaultButtonSize.y),
                Title = nTitle,
                BackgroundColor = new Color(0.8f, 0.8f, 0.8f),
                FontSize = 20
            };
            if (nAction != null)
            {
                NegativeButtonView.AddListener(nAction);
            }

            NegativeButtonView.AddListener(Destroy);
        }

        public static Sprite DefaultBackgroundSprite = null;
    }

    public class UIInfoDialog : AbsDialog
    {

    }
}